package com.design.pattern.state;

import java.util.Random;

public class HasQuarterState implements State {

    GumballMachine gumballMachine;

    public HasQuarterState(GumballMachine gumballMachine) {
        this.gumballMachine = gumballMachine;
    }

    public void insertQuarter() {
        System.out.println("你已经投了钱了，别投钱了");
    }

    public void ejectQuarter() {
        System.out.println("马上退钱给你");
        gumballMachine.setState(gumballMachine.getNoQuarterState());
    }

    public void turnCrank() {
        System.out.println("你摇动了摇杆");

        int win = new Random().nextInt(10);
        if (win == 0 && gumballMachine.getCount() > 1) {
            gumballMachine.setState(gumballMachine.getWinState());
        } else {
            gumballMachine.setState(gumballMachine.getSoldState());
        }
    }

    public void dispense() {
        System.out.println("你还没摇动摇杆呢，不能给你糖");
    }
}